/**
 *
 */
Ext.define('vacake.view.Users', {
    extend: 'Ext.Container',
    xtype: 'usersView',
    requires: [
        'Ext.Img'
    ],
    config: {
        items: [
            {
                docked: 'top',
                xtype: 'titlebar',
                title: '我的'
            },
            {
                xtype: 'panel',
                layout: {type: 'vbox'},
                items: [
                    {
                        xtype: 'panel',
                        layout: 'hbox',
                        style:'margin:10px 20px',
                        items: [
                            {
                                xtype: 'image',
                                src: '',
                                cls:'radius',
                                id: 'user_image',
                                height: 91,
                                width: 92
                            },
                            {
                                xtype: 'panel',
                                layout: 'vbox',
                                style:'margin:0px 20px',
                                items: [
                                    {
                                        xtype: 'label',
                                        cls:'font6 color2 height30',
                                        id: 'showName',
                                        html: ''
                                    },
                                    {
                                        xtype: 'panel',
                                        layout: 'hbox',
                                        items: [
                                            {
                                                xtype: 'label',
                                                cls:'font2 color3 height30',
                                                html: '会员级别：'
                                            },
                                            {
                                                xtype: 'label',
                                                cls:'font2 color3 height30',
                                                id: 'showLevel',
                                                html: '普通会员'
                                            }

                                        ]
                                    },
                                    {
                                        xtype: 'panel',
                                        layout: 'hbox',
                                        items: [
                                            {
                                                xtype: 'label',
                                                cls:'font2 color3 height20',
                                                html: '您的余额：'
                                            },
                                            {
                                                xtype: 'label',
                                                cls:'font2 color3 height20',
                                                id: 'showBalance',
                                                html: '0.0'
                                            },
                                            {
                                                xtype: 'label',
                                                cls:'font2 color3 height20',
                                                html: '元'
                                            }

                                        ]
                                    }

                                ]
                            }
                        ]
                    },
                    {cls:'fenge'},
                    {
                        xtype: 'panel',
                        layout: {type: 'hbox', align: 'middle', pack: 'center'},
                        items: [
                            {
                                xtype: 'fieldset',
                                cls: 'x-area2',
                                flex:'1',
                                //width: '33%',
                                items: [
                                    {
                                        xtype: 'label',
                                        cls:'center font1 color2',
                                        html:'<img src="resources/images/users_menu_1.png" width="100%"><br><span style="font-size:14px">当前订单</span>',
                                        id: 'currentOrder',
                                        listeners: {
                                            painted: function (label) {
                                                label.on('tap', function () {
                                                    Ext.Viewport.mask({xtype: 'loadmask', message: '加载数据中...'  });
                                                    Ext.Viewport.animateActiveItem('usersCurrent', {type: 'slide', direction: 'left'});
                                                    return false;
                                                }, this);
                                            }
                                        }
                                    }
                                ]
                            } ,
                            {
                                xtype: 'fieldset',
                                cls: 'x-area2',
                                flex:'1',
                                //width: '33%',
                                items: [
                                    {
                                        xtype: 'label',
                                        cls:'center font1 color2',
                                        html:'<img src="resources/images/users_menu_2.png" width="100%"><br><span style="font-size:14px">已完成订单</span>',
                                        id: 'finishOrder',
                                        listeners: {
                                            painted: function (label) {
                                                label.on('tap', function () {
                                                    Ext.Viewport.mask({xtype: 'loadmask', message: '加载数据中...'  });
                                                    Ext.Viewport.animateActiveItem('usersFinish', {type: 'slide', direction: 'left'});
                                                    return false;
                                                }, this);
                                            }
                                        }
                                    }
                                ]
                            } ,
                            {
                                xtype: 'fieldset',
                                cls: 'x-area2',
                                flex:'1',
                                //width: '33%',
                                items: [
                                    {
                                        xtype: 'label',
                                        cls:'center font1 color2',
                                        html:'<img src="resources/images/users_menu_3.png" width="100%"><br><span style="font-size:14px">收藏</span>',
                                        id: 'collect',
                                        listeners: {
                                            painted: function (label) {
                                                label.on('tap', function () {
                                                    Ext.Viewport.mask({xtype: 'loadmask', message: '加载数据中...'  });
                                                    Ext.Viewport.animateActiveItem('usersCollect', {type: 'slide', direction: 'left'});
                                                    return false;
                                                }, this);
                                            }
                                        }
                                    }
                                ]
                            }
                        ]
                    },
                    {
                        xtype: 'panel',
                        layout: {type: 'hbox', align: 'middle', pack: 'left'},
                        items: [
                            {
                                xtype: 'fieldset',
                                cls: 'x-area2',
                                flex:'1',
                                //width: '33%',
                                items: [
                                    {
                                        xtype: 'label',
                                        cls:'center font1 color2',
                                        html:'<img src="resources/images/users_menu_4.png" width="100%"><br><span style="font-size:14px">收货地址</span>',
                                        id: 'shippingAddress',
                                        listeners: {
                                            painted: function (label) {
                                                label.on('tap', function () {
                                                    Ext.Viewport.mask({xtype: 'loadmask', message: '加载数据中...'  });
                                                    Ext.Viewport.animateActiveItem('usersAddress', {type: 'slide', direction: 'left'});
                                                    return false;
                                                }, this);
                                            }
                                        }
                                    }
                                ]
                            } ,
                            // {
                            //     xtype: 'fieldset',
                            //     cls: 'x-area',
                            //     width: '33%',
                            //     items: [
                            //         {
                            //             xtype: 'label',
                            //             cls:'center',
                            //             html:'<img src="resources/images/users_menu_5.png" width="100%"><br><span style="font-size:14px">生日提醒</span>',
                            //             id: 'birthdayReminder'
                            //         }
                            //     ]
                            // } ,
                             {
                                xtype: 'fieldset',
                                cls: 'x-area2',
                                 flex:'1',
                                //width: '33%',
                                id: 'moreImage',
                                items: [
                                    {
                                        xtype: 'label',
                                        cls:'center font1 color2',
                                        html:'<img src="resources/images/users_menu_6.png" width="100%"><br><span>更多</span>',
                                        listeners: {
                                            painted: function (label) {
                                                label.on('tap', function (){
                                                    this.getParent().fireEvent('onTap');
                                                    return false;
                                                }, this);
                                            }
                                        }
                                    }
                                ]
                            },
                            {
                                flex:1
                            }
                        ]
                    }
                ]
            }

        ],
        listeners: {
            painted: function () {
                if (window.localStorage.getItem('app_Login_id') != null) {
                    var users = Ext.getStore('Users');
                    if(users.find('cuid',window.localStorage.getItem('app_Login_id'))==-1){
                    users.load({params: {cuid: window.localStorage.getItem('app_Login_id')},
                        callback: function (data) {
                            var user = data[0];
                            Ext.getCmp('showName').setHtml(user.get('name'));
                        }});
                    }
                    Ext.getCmp('user_image').setSrc(window.localStorage.getItem('app_Login_avatar'));
                }
                Ext.Viewport.unmask();
            }
        }
    }

});

